#!/bin/sh
#
# Script to initiate a ppp connection. This is the first part of the
# pair of scripts. This is not a secure pair of scripts as the codes
# are visible with the 'ps' command.  However, it is simple.
# Modify: jiangyanfeng@gmail.com
# These are the parameters. Change as needed.
DEVICE=$1
#TELEPHONE=$2            # The telephone number for the connection
ACCOUNT=$3              # The account name for logon
PASSWORD=$4     	# The password for this account
AUTHENTICATION=$5	# The authentication protocal
export COLUMNS=256

if [ "$5" = "" ]; then
        LOCAL_IP=0.0.0.0
else
        LOCAL_IP=$5
fi

if [ "$6" = "" ]; then
        REMOTE_IP=0.0.0.0
else
        REMOTE_IP=$6
fi

if [ ! "$7" = "" ]; then
	USEPEERDNS=''
	for NAMESERVER in `echo $7 | awk -F: '{for (i=1;i<=NF;i++) print $i}'`
	do
        	echo "nameserver $NAMESERVER" >> /etc/ppp/resolv.conf
	done
else
	USEPEERDNS='usepeerdns'
fi

NETMASK=255.255.255.0	# The proper netmask if needed
#
# Export them so that they will be available at 'ppp-on-dialer' time.
export TELEPHONE APN ACCOUNT PASSWORD 
# 
# This is the location of the script which dials the phone and logs
# in.  Please use the absolute file name as the $PATH variable is not
# used on the connect option.  (To do so on a 'root' account would be
# a security hole so don't ask.)
#
DIALER_SCRIPT=/usr/local/hw_pppd/etc/ppp/huawei-ppp-on-dialer
# Initiate the connection
# 
# I put most of the common options on this command. Please, don't
# forget the 'lock' option or some programs such as mgetty will not
# work. The asyncmap and escape will permit the PPP link to work with
# a telnet or rlogin connection. You are welcome to make any changes
# as desired. Don't use the 'defaultroute' option if you currently
# have a default route to an ethernet gateway.
#

/usr/local/hw_pppd/sbin/pppd linkname HuaweiMobile telephone "$2" $AUTHENTICATION lock crtscts modem $DEVICE 115200 $USEPEERDNS noauth noipdefault defaultroute name "$ACCOUNT" password "$PASSWORD" connect $DIALER_SCRIPT

